package com.lingnan.cmsservice.controller;


import com.lingnan.cmsservice.entity.CrmBanner;
import com.lingnan.cmsservice.service.CrmBannerService;
import com.lingnan.common.utils.ResultEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;


import java.util.List;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author zzd
 * @since 2021-08-30
 */
@RestController
@RequestMapping("/cmsService/crmbanner")
@Api("banner前台功能")
@CrossOrigin
public class CrmForntBannerController {
    @Autowired
    private CrmBannerService bannerService;


    /**
     * 查询时间最靠前的5条banner信息
     * @Cacheable:设置Redis缓存
     * @return
     */
    @Cacheable(value = "banner",key = "'findBanner'")
    @GetMapping("findBanner")
    @ApiOperation("查询所有banner")
    public ResultEntity findBanner() {
        try {
            // 调用Serivce执行查询操作
            List<CrmBanner> crmBannerList = bannerService.findBanner();

            return ResultEntity.ok().data("bannerList", crmBannerList);

        } catch (Exception e) {

            e.printStackTrace();

            return ResultEntity.error();
        }
    }

}

